<%@page import="cn.jdy.authority.entity.SysMenu"%>
<%@page import="java.util.List"%>
<%@ page import="cn.jdy.authority.entity.User" %>
<%@ page import="cn.jdy.authority.service.SysMenuService" %>
<%@ page import="cn.jdy.framework.util.SpringContextUtils" %>
<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    SysMenuService sysMenuService = SpringContextUtils.getBean(SysMenuService.class);
    request.setAttribute("menus", sysMenuService.getUserMenu(((User)session.getAttribute("user")).getId()));
    session.setAttribute("resourceList", sysMenuService.findUserMenu(((User)session.getAttribute("user")).getId())) ; // 用户可以访问的资源地址列表
    session.setAttribute("dbmenus", sysMenuService.listSysMenu(true)); // 数据库中所有的菜单URL地址
%>
    <div class="page-sidebar navbar-collapse collapse">
        <ul class="page-sidebar-menu" data-auto-scroll="true" data-slide-speed="200" style="height: 100%;">
 			<li class="sidebar-toggler-wrapper">
	            <div class="sidebar-toggler hidden-phone" style="height: 30px;" title='点击收缩/展开菜单'>
	            </div>
			</li>
        <c:forEach items="${menus}" var="topMenu" varStatus="i">
            <c:choose>
                <c:when test="${topMenu.children == null}">
                    <li id="m${i.index}" onclick="App.storeMenu('m${i.index}')">
                    <a href="${fn:startsWith(topMenu.url, 'http') ? '' : path.concat('/')}${topMenu.url}">
                    <i class="fa ${topMenu.menuimg}"></i> <span class="title">${topMenu.menuname}</span>
                    <span class="selected"></span></a></li>
                </c:when>
				<c:otherwise>
					<li id="m${i.index}"><a href="javascript:void(0)"><i class="fa ${topMenu.menuimg}"></i> 
					<span class="title">${topMenu.menuname}</span>
					<span class="arrow"></span><span class="selected"></span></a>
					<ul class="sub-menu">
							<c:forEach items="${topMenu.children}" var="twoMenu" varStatus="j">
								<li id="m${i.index}_${j.index}" onclick="App.storeMenu('m${i.index}_${j.index}')">
								<a href="${fn:startsWith(twoMenu.url, 'http') ? '' : path.concat('/')}${twoMenu.url}">
								<i class="fa ${twoMenu.menuimg}"></i> 
								<span class="title">${twoMenu.menuname}</span>
								<span class="selected"></span>
								</a>
								</li>
							</c:forEach>
						</ul></li>
				</c:otherwise>
			</c:choose>
        </c:forEach>
    </ul>
</div>
